<template>
  <div>
    <el-table v-loading="listLoading" ref="table" :stripe="true" :data="list" style="width: 100%">
      <el-table-column label="结账单号" min-width="80">
        <template slot-scope="scope">
          <span>{{ scope.row['结账单号'] }}</span>
        </template>
      </el-table-column>

      <el-table-column label="生成日期" align="center" min-width="100">
        <template slot-scope="scope">
          <span>{{ scope.row['时间'] }}</span>
        </template>
      </el-table-column>

      <el-table-column label="待结总额(元)" align="center" min-width="140">
        <div slot-scope="scope" class="font12">
          <span>{{ scope.row['总价'] }}</span>
        </div>
      </el-table-column>
      <el-table-column label="送票人" align="center" min-width="140">
        <div slot-scope="scope" class="font12">
          <span>{{ scope.row['送票人'] }}</span>
        </div>
      </el-table-column>
      <el-table-column label="送票人联系方式" align="center" min-width="140">
        <div slot-scope="scope" class="font12">
          <span>{{ scope.row['送票人联系方式'] }}</span>
        </div>
      </el-table-column>
      <el-table-column label="发票号" align="center" min-width="120">
        <div slot-scope="scope" class="font12">
          <span>{{ scope.row['发票号'] }}</span>
        </div>
      </el-table-column>

      <el-table-column label="操作" min-width="250" align="center">
        <template slot-scope="scope">
          <!-- <el-button type="text" @click="tableDatatwo(scope.row)">详情</el-button> -->
          <el-button type="text" @click="confirmTicket(scope.row)">撤回</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { fetchList } from '@/api/api'
export default {
  data() {
    return {
      listLoading: false,
      list: []
    }
  },
  created() {
    this.getList()
    this.bus.$on('refreshJiezhang', () => {
      this.getList()
    })
  },
  methods: {
    getList() {
      this.listLoading = true
      const param = {
        query: 'vue_供货商撤回发票list',
        供货商编号: localStorage.ghusername
      }
      fetchList(param).then(({ data }) => {
        console.log(data)
        if (data.flag === '0') {
          this.list = []
        } else {
          this.list = data.data
        }
        this.listLoading = false
      })
    },
    confirmTicket(row) {
      this.$confirm('您确定撤回吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const param = {
          query: 'vue_供货商撤回发票更新',
          结账单号: row.结账单号
        }
        fetchList(param).then(({ data }) => {
          if (data.flag === '1') {
            this.$message.success('更新成功,请到待填写发票结账单继续操作')
            this.getList()
          } else {
            this.$message.error('更新失败')
          }
          this.bus.$emit('refreshJiezhang')
        })
      })
    }
  }
}
</script>

<style>
</style>
